<!--登录页-->
<template>
  <div style="height:100vh;
             background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.3) 100%), url('/login.png');
             background-size: cover;
             overflow:hidden;">
    <el-container style="padding:30px;">
      <el-header>

      </el-header>
      <el-main>
        <el-row :gutter="40">
          <el-col :span="8">
          </el-col>
          <el-col :span="8">
            <el-card style="width:100%;margin-top:60px;background-color: rgba(255, 255, 255, 0) ">
              <h1 style="text-align:center; color: white">WELCOME TO WANLIU</h1>
              <h1 style="text-align:center; color: white">智慧物业管理系统后台登录</h1>
              <el-form label-position="top">
                <el-form-item>
                  <el-input placeholder="请输入用户名" v-model="user.username"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-input placeholder="请输入密码" type="password" v-model="user.password"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" style="width:100%;margin-top: 10px" @click="login()">登录</el-button>
                </el-form-item>
              </el-form>
            </el-card>
              <div style="color:lightgray;text-align:center;font-size:14px;padding:10px 0;">
                (体验账号:admin 密码:admin)
              </div>
          </el-col>
        </el-row>
      </el-main>
    </el-container>
  </div>
</template>



<script setup>
import {ref} from "vue";
import qs from "qs";
import axios from "axios";
import {ElMessage} from "element-plus";
import router from "@/router";

const user=ref({username:'',password:''});
const login = () => {
  let data=qs.stringify(user.value);
  console.log(data);
  axios.post(BASE_URL+'/v1/user/login', data).then(response => {
    if (response.data.code == 2000) {
      ElMessage.success('登录成功!');
      localStorage.user = JSON.stringify(response.data.data);
      router.push('/workspace');
    } else {
      ElMessage.error(response.data.msg);
    }
  })
}
</script>

<style scoped>
</style>